package TestModel;

import java.util.LinkedList;

import WhiteSpaceReport.WhiteSpaceByRect;

import DataModel.CommonLibrary.CommonDefs;
import DataModel.LayoutManager.CRectangle;
import junit.framework.TestCase;

public class whiteSpaceTest extends TestCase {
	
	private CRectangle area;
	
	
	private CRectangle u1;
	private CRectangle u2;
	private CRectangle u3;
	private CRectangle u4;
	private CRectangle u5;
	
	private CRectangle r1;
	private CRectangle r2;
	private CRectangle r3;
	private CRectangle r4;
	private CRectangle r5;
	private CRectangle r6;
	private CRectangle r8;
	private CRectangle r9;
	private CRectangle r10;
	private CRectangle r11;
	
	private CRectangle yr1;
	private CRectangle yr2;
	private CRectangle yr3;
	private CRectangle yr4;
	private CRectangle yr5;
	private CRectangle yr6;
	private CRectangle yr7;
	private CRectangle yr8;
	private CRectangle yr9;
	private CRectangle yr10;
	private CRectangle yr11;
	
	
	
	private LinkedList<CRectangle> urecs;
	private LinkedList<CRectangle> resExpectedX;
	private LinkedList<CRectangle> resExpectedY;
	
	private void initTest() {
		area = new CRectangle(0,0,10,10,CommonDefs.Layer.None, 0);
		
		u1 = new CRectangle(1,2,3,6,CommonDefs.Layer.Metal1,1);
		u2 = new CRectangle(2,5,7,7,CommonDefs.Layer.Metal1,2);
		u3 = new CRectangle(2,0,7,3,CommonDefs.Layer.Metal1,3);
		u4 = new CRectangle(6,2,10,6,CommonDefs.Layer.Metal1,4);
		u5 = new CRectangle(1,7,10,9,CommonDefs.Layer.Metal1,5);
		urecs =  new LinkedList<CRectangle>();
		urecs.add(u1);
		urecs.add(u2);
		urecs.add(u3);
		urecs.add(u4);
		urecs.add(u5);
		resExpectedX =  new LinkedList<CRectangle>();
		r1 = new CRectangle(0,0,2,2,CommonDefs.Layer.None,-1);
		r2 = new CRectangle(7,0,10,2,CommonDefs.Layer.None,-1);
		r3 = new CRectangle(0,2,1,3,CommonDefs.Layer.None,-1);
		r4 = new CRectangle(0,3,1,5,CommonDefs.Layer.None,-1);
		r5 = new CRectangle(3,3,6,5,CommonDefs.Layer.None,-1);
		r6 = new CRectangle(0,5,1,6,CommonDefs.Layer.None,-1);
		r8 = new CRectangle(0,6,2,7,CommonDefs.Layer.None,-1);
		r9 = new CRectangle(7,6,10,7,CommonDefs.Layer.None,-1);
		r10 = new CRectangle(0,7,1,9,CommonDefs.Layer.None,-1);
		r11 = new CRectangle(0,9,10,10,CommonDefs.Layer.None,-1);
		resExpectedX.add(r1);
		resExpectedX.add(r2);
		resExpectedX.add(r3);
		resExpectedX.add(r4);
		resExpectedX.add(r5);
		resExpectedX.add(r6);
		resExpectedX.add(r8);
		resExpectedX.add(r9);
		resExpectedX.add(r10);
		resExpectedX.add(r11);

		resExpectedY =  new LinkedList<CRectangle>();
		yr1 = new CRectangle(0,0,1,10,CommonDefs.Layer.None,-1);
		yr2 = new CRectangle(1,0,2,2,CommonDefs.Layer.None,-1);
		yr3 = new CRectangle(1,6,2,7,CommonDefs.Layer.None,-1);
		yr4 = new CRectangle(1,9,2,10,CommonDefs.Layer.None,-1);
		yr5 = new CRectangle(2,9,3,10,CommonDefs.Layer.None,-1);
		yr6 = new CRectangle(3,3,6,5,CommonDefs.Layer.None,-1);
		yr7 = new CRectangle(3,9,6,10,CommonDefs.Layer.None,-1);
		yr8 = new CRectangle(6,9,7,10,CommonDefs.Layer.None,-1);
		yr9 = new CRectangle(7,0,10,2,CommonDefs.Layer.None,-1);
		yr10 = new CRectangle(7,6,10,7,CommonDefs.Layer.None,-1);
		yr11 = new CRectangle(7,9,10,10,CommonDefs.Layer.None,-1);
		resExpectedY.add(yr1);
		resExpectedY.add(yr2);
		resExpectedY.add(yr3);
		resExpectedY.add(yr4);
		resExpectedY.add(yr5);
		resExpectedY.add(yr6);
		resExpectedY.add(yr7);
		resExpectedY.add(yr8);
		resExpectedY.add(yr9);
		resExpectedY.add(yr10);
		resExpectedY.add(yr11);

		

	}
	
	public void testWhiteTest() {
		initTest();
		LinkedList<CRectangle> freeArea;
		System.out.println("Direction x..........");
		freeArea = WhiteSpaceByRect.findWhiteSpaceByRect(area,urecs,  'x'); 
		CRectangle.printRecsList(freeArea);
		for (int i =0;i<resExpectedX.size();i++) {
			assertEquals(resExpectedX.get(i).toString(), freeArea.get(i).toString());
		}
		CRectangle.printRecsList(freeArea);
		
		System.out.println("Direction y..........");
		freeArea = WhiteSpaceByRect.findWhiteSpaceByRect(area,urecs,  'y'); 
		for (int i =0;i<resExpectedY.size();i++) {
			assertEquals(resExpectedY.get(i).toString(), freeArea.get(i).toString());
		}
		
		CRectangle.printRecsList(freeArea);
		assertTrue(true);
		
	}
}
